package com.spoplar.test;

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;

public class TopicsConsumer {

	private static final String USER = ActiveMQConnection.DEFAULT_USER;
	private static final String PASS = ActiveMQConnection.DEFAULT_PASSWORD;
	private static final String BROKER_URL = ActiveMQConnection.DEFAULT_BROKER_URL;
	
	public static void main(String[] args) throws JMSException {
		
		ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(USER,PASS,BROKER_URL);
		
		Connection connection = factory.createConnection();
		
		connection.start();
		
		
		Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
		
		Destination destination = session.createTopic("new topics");
		
		MessageConsumer consumer =  session.createConsumer(destination);
		
		//Message message = consumer.receive();
		
		consumer.setMessageListener(new MessageListener() {
			
			@Override
			public void onMessage(Message msg) {
				String str;
				try {
					str = ((TextMessage)msg).getText();
					System.out.println(str);
				} catch (JMSException e) {
					e.printStackTrace();
				}
				
			}
		});
		
		
		
	}
	
	
}
